﻿@model Tyshka.Subroutines.ViewModels.DetailViewModel

@{
    ViewBag.Title = "Detail";
}

<div class="row">
    <div class="span8">
	    <div class="bright_block">
		    <div class="row">
				<div class="span5">
					<h1>@Model.Title</h1>
					<h4>Written by @Model.Author</h4>
					<h4>@Model.DateAdded</h4>						
				</div>
				<div style="float:right; text-align:center; margin-top:15px;">
						<span class="badge @Model.BadgeCssStyle">@Model.Votes</span>
                        @if (Model.IsCanVote)                        {
								<div class="btn-group" style="margin-top:15px;">
									<a class="btn" href="@Url.Action("DownVote", "Subroutine", new { id = Model.Id })"><i class="icon-minus"></i></a>
									<a class="btn" href="@Url.Action("UpVote", "Subroutine", new { id = Model.Id })"><i class="icon-plus"></i></a>
								</div>
                        }
				</div>
			</div>

                        @if (Model.UploadAllowed)
                        {
                        <div class="row" style="margin-top:25px;">
                            <div class="span7">
                                @Url.SubroutineEditLink(Model.Id, "Edit subroutine", "btn btn-primary btn-large")
                                @Url.SubroutineDeleteLink(Model.Id, "Delete subroutine", "btn btn-danger")                                
                            </div>
                        </div>
                        }
					
			<div class="row" style="margin-top:25px;">
				<div class="span7">
					Tags:
                        @foreach(var tag in Model.Tags) {
                            <a href="@Url.Action("Detail", "Tag", new { id = @tag.Key })"><span class="label label-info">@tag.Value</span></a>
                        }
				</div>
			</div>
		</div>
		<div class="bright_block">
			<h2>Short Description</h2>
			@Model.Description
		</div>
	</div>
	<div class="span4 dcpu_logo">
		<!-- -->
	</div>
</div>

<div class="row">
    <div class="span12">
        <div class="bright_block">
            <h2>Input Parameters <small>Stack parameters or registers used as function inputs</small></h2>
            @if (Model.IsAnyRegisterParams)
            {
                foreach(var param in Model.RegisterParams){
                    <div><span class="badge badge-inverse">@param.Name</span> - @param.Comment</div>
                }
            }
            else
            {
                <div>No register parameters.</div>
            }
            @if (Model.IsAnyStackParams)
            {
                <h4 style="margin-top:10px;">Stack parameters</h4>
                
					<table class="table table-striped">
						<thead>
							<tr>
								<th>Address</th>
								<th>Description</th>
							</tr>
						</thead>
						<tbody>
                @foreach (var stack in Model.StackParams)
                {
                    <tr>
                    <td>[SP+@stack.Offset]</td>
                    <td>@stack.Comment</td>
                    
                    </tr>
                }
                </tbody>
                </table>

            }
            else
            {
                <div>No stack params.</div>
            }
            <h2 style="margin-top:20px;">Output Parameters <small>List of registers changed as a result of subroutine call</small></h2>
            @if (Model.IsAnyOutput)
            {
                foreach(var param in Model.OutputParams){
                    <div><span class="badge badge-inverse">@param.Name</span> - @param.Comment</div>
                }
            }
            else
            {
                <div>No register parameters.</div>
            }
        </div>
    </div>
</div>

<div class="row">
	<div class="span12">				
		<div class="bright_block">
			<h2>Code</h2>
            <p><a href="@Url.Action("Raw", "Subroutine", new { id = Model.Id })" class="btn btn-info">Raw version</a></p>
			<pre class="prettyprint linenums lang-vhdl">
@Model.Code
			</pre>
		</div>
	</div>
</div>

<div class="row">
	<div class="span12">	
		<div class="bright_block">
    		<h2>Alternative implementations:</h2>

            @if (Model.HasAlts)
            {
                <ul>
                @foreach (var alt in Model.Alts)
                {
                    <li>@Url.SubroutineDetailLink(alt.Id, alt.Name) by @alt.Author <span class="badge @alt.VotesCssClass">@alt.Votes</span></li>

                }
                </ul>
            }
            else
            {
                <div>No alternative implementations.</div>
            }

		</div>
	</div>
</div>

<div class="row">
	<div class="span12">	
		<div class="bright_block">
    		<h2>Dependencies <small>Subroutines used in this subroutine</small></h2>
            @if (Model.HasDeps)
            {
                <ul>
                @foreach (var alt in Model.Deps)
                {
                    <li>@Url.SubroutineDetailLink(alt.Id, alt.Name) by @alt.Author <span class="badge @alt.VotesCssClass">@alt.Votes</span></li>

                }
                </ul>
            }
            else
            {
                <div>No subroutines used.</div>
            }
		</div>
	</div>
</div>
			
			
